package com.sample.FinalProject;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class FinalProjectActivity extends Activity implements OnClickListener{
	FinalView fv;
	CustomApp ca;
	Button button1;
	Bundle bundle;
	Bundle oldBundle;
	Intent intentMain;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.d("debug", "created");
        ca=(CustomApp)this.getApplication();
        fv=(FinalView)findViewById(R.id.finalView1);
        fv.setTextView((TextView) findViewById(R.id.textView1));
        ca.setFinal(fv.getFinal());
        button1=(Button)findViewById(R.id.button1);
        button1.setOnClickListener(this);
        intentMain = new Intent(/*FinalProjectActivity.*/this , MenuActivity.class);
    }
    public void onRestart(){
    	
    }
    public void onPause(){
    super.onPause();	
    finish();
    }
    public void onStop(){
    	super.onStop();
    	finish();
    	}
    public void onResume(){
    	super.onResume();
    	bundle=getIntent().getBundleExtra("aBundle");
        if(bundle != null && bundle != oldBundle){
        fv.unpackMenuBundle(bundle);	
        oldBundle=bundle;
        }
        try{
        	fv.restore(ca.getBuilding(),ca.getTowers(),ca.getSquares(),ca.getCircleUnits());
        	}
        catch(NullPointerException E){}
        }
	public void onClick(View v) { 
		if (v.getId()== button1.getId()){
		try{
			ca.setBuilding(fv.getBuilding());
			ca.setTowers(fv.getTowers());
			ca.setSquares(fv.getSquares());
			ca.setCircleUnits(fv.getCircleUnits());
			intentMain.putExtra("aBundle", fv.makeMenuBundle());
			intentMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		    /*FinalProjectActivity.this.*/startActivity(intentMain);
		    finish();
		    Log.d("debug", "test5");
		}
		catch(NullPointerException E){
			
		}
		}
	}
}